package com.fs.controller;


import com.fs.domain.Orders;
import com.fs.domain.OrdersCanceled;
import com.fs.domain.vo.OrderSearchDTO;
import com.fs.domain.vo.ResultCode;
import com.fs.service.ServeOrdersService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

import static com.fs.domain.vo.ResultCode.FAILED;
import static com.fs.domain.vo.ResultCode.SUCCESS;
import static com.ruoyi.common.utils.PageUtils.startPage;

/**
 * @Description
 * @Author susu
 * @Date 2024/10/15
 */
@RestController
@RequestMapping("/serve")
public class ServeOrdersController extends BaseController {

    //引用服务层
    @Resource
    private ServeOrdersService serveOrdersService;

    /**
     *
     * @param
     * @return
     */
    @GetMapping("/query/orders")
//    @PreAuthorize("@ss.hasPermission('trade:brokerage-record:query')")
    public TableDataInfo orderInquiries(){
        startPage();
        List<Orders> orders = serveOrdersService.ordersAll();
        return getDataTable(orders);
    }

    /**
     *  新增取消订单，订单状态修改，历史订单状态修改
     * @param ordersCanceled
     * @return
     */
    @PostMapping(value = "/add/orders_canceled")
    public ResultCode addOrdersCanceled(OrdersCanceled ordersCanceled){
        //新增取消订单
        Integer i = serveOrdersService.addOrdersCanceled(ordersCanceled);

        if (i>0){
          return SUCCESS;
        }
        return FAILED;
    }

    /**
     * 通过条件查询订单
     * @param orderSearchDTO 通过订单编号 客户支付状态 下单时间 订单状态 支付状态 退款状态
     * @return 查询到的订单
     */
    @GetMapping("/search")
    public TableDataInfo searchOrders(OrderSearchDTO orderSearchDTO) {
        startPage();
        List<Orders> orders = serveOrdersService.likeQueryQrders(orderSearchDTO);
        return getDataTable(orders);
    }

    /**
     * 通过id查找订单详细信息
     * @param id
     * @return
     */
    @GetMapping(value = "/orderById/{id}")
    public TableDataInfo selectOrderById(@PathVariable("id")Long id){
        List<Orders> orders = serveOrdersService.selectOrderById(id);
        return getDataTable(orders);
    }

    /**
     * 修改订单
     */
//    @PreAuthorize("@ss.hasPermi('system:orders:edit')")
    @PutMapping("/update")
    public AjaxResult edit(@RequestBody Orders orders)
    {
        return toAjax(serveOrdersService.updateOrders(orders));
    }

    /**
     *
     * @param serveItemName 服务类型
     * @return 该类型的订单数
     */
    @GetMapping("/ordersByType/{serveItemName}")
    public int ordersByType(@PathVariable("serveItemName")String serveItemName){
        return serveOrdersService.ordersByType(serveItemName);
    }

}

